import * as types from "../types/recycleAccessResultTypes";

const initialState = {
  loading: false,
  initing: true,
  error: undefined,
  facilitySign: "",
  dateTime: new Date(),
  data: {},
  recycleTypeList: [],
  curRecycleWayIndex: 0,
  realType: 1,
  address: undefined,
  stationName: { station_name: "呼兰路", line_name: "1号线" },
  stationCode: {
    line_id: 100,
    station_id: 124,
  },
};

export default function recycleAccessResultReducer(state = initialState, action) {
  switch (action.type) {
    case types.RECYCLEACCESSRESULT_LOADING:
      return {
        ...state,
        loading: true,
      };
    case types.RECYCLEACCESSRESULT_PLANORDER_DONE:
      return {
        ...state,
        loading: false,
      };
    case types.RECYCLEACCESSRESULT_INIT:
      return {
        ...state,
        dateTime: new Date(),
        initing: true,
      };
    case types.RECYCLEACCESSRESULT_DONE:
      return {
        ...state,
        initing: false,
        loading: false,
        data: action.data,
        facilitySign: action.facilitySign,
        recycleTypeList: action.recycleTypeList,
      };
    case types.RECYCLEACCESSRESULT_ERROR:
    case types.RECYCLEACCESSRESULT_INIT_ERROR:
      return {
        ...state,
        initing: false,
        loading: false,
        error: action.error,
      };
    case types.RECYCLEACCESSRESULT_CHANGE_RECYCLEWAY:
      return {
        ...state,
        curRecycleWayIndex: action.curRecycleWayIndex,
      };
    case types.RECYCLEACCESSRESULT_CHANGE_REALWAY:
      return {
        ...state,
        realType: action.realType,
      };
    case types.RECYCLEACCESSRESULT_CHANGE_ADDRESS:
      return {
        ...state,
        address: action.address,
      };
    case types.RECYCLEACCESSRESULT_CHANGE_DATETIME:
      return {
        ...state,
        dateTime: action.dateTime,
      };
    case types.RECYCLEACCESSRESULT_CHANGE_SUBWAYNAME:
      return {
        ...state,
        stationName: action.stationName,
      };
    case types.RECYCLEACCESSRESULT_CHANGE_SUBWAYCODE:
      return {
        ...state,
        stationCode: action.stationCode,
        loading: false,
      };
    case types.RECYCLEACCESSRESULT_UNMOUNT:
      return {
        ...initialState,
      };
    default:
      return state;
  }
}
